﻿using Tfs.OnTheRoad.ViewModel;
namespace Tfs.OnTheRoad.Commands
{
    /// <summary>
    /// Selects a Profile from the Project List Window(MainPage.aspx)
    /// </summary>
    public class SelectProfileCommand : BaseCommand<ProjectListViewModel>
    {
        public SelectProfileCommand(ProjectListViewModel owner)
            : base(owner)
        {

        }

        public override void Execute(object parameter)
        {
            System.Windows.Controls.SelectionChangedEventArgs args = parameter as System.Windows.Controls.SelectionChangedEventArgs;
            if (args != null && args.AddedItems.Count > 0)
            {
                // Set the selected item as the current item.
                var selectedProfile = args.AddedItems[0] as SettingsViewModel;
                App.SettingsViewModel = selectedProfile;
                Owner.RecreateContext();
                Owner.LoadData();
            }                 
        }
    }
}